//
// Created by yewei on 2023/1/9.
//
#include <bits/stdc++.h>

using namespace std;

struct stu{
    string name;
    int score;
};

bool cmp(stu a, stu b){
    return a.score != b.score ? a.score<b.score : a.name<b.name;
}

int main() {
    freopen("../input.txt", "r", stdin);
    int T;
    cin>>T;
    int n,Q;
    while(T--){
        cin>>n;
        struct stu stu[n];
        for(int i=0;i<n;i++) cin>>stu[i].name>>stu[i].score;
        sort(stu,stu+n,cmp);
        cin>>Q;
        int s;
        while(Q--){
            cin>>s;
            int flag = 0,pre;
            for(int i=0;i<n;i++) {
                if(flag && stu[i].score==pre) cout<<" "<<stu[i].name;
                else if(flag) break;
                if(stu[i].score>s) {
                    pre = stu[i].score;
                    cout<<stu[i].name;
                    flag = 1;
                }
            }
            if(!flag) cout<<"Impossible";
            cout<<endl;
        }
    }
}
